#ifndef FACEAUTHENTICATECV_H
#define FACEAUTHENTICATECV_H

#include "faceauthinterface.h"

#ifdef USE_OPENCV
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/face.hpp>
#include <stdio.h>

using namespace std;
using namespace cv;
using namespace face;


#define CVModel Ptr<LBPHFaceRecognizer>
/**
 * @brief The FaceAuthenticateCV class
 * based on opencv LBPHFaceRecognizer (Local Binary Patterns Histogram)
 * alternative : LBPH/EigenFishfaces/Fisherfaces
 */
class FaceAuthenticateCV : public FaceAuthInterface
{
public:
    explicit FaceAuthenticateCV(QObject *parent = nullptr);
    virtual ~FaceAuthenticateCV();

    virtual FaceAuthResult init();
    virtual FaceAuthResult finit();
    virtual FaceAuthResult face_detect(void* datainput, void* dataoutput);
    virtual FaceAuthResult face_regist(const QString key, void* datainput);
    virtual FaceAuthResult face_predict(void* datainput, FaceRecogResult& result);

    void initFromModelPath(const QList<QString>& model_paths, const QString& detect_path);
    QList<QString> getLabels();
    bool isLableExists(const QString& label);
    void removeFaceLabel(const QString& label);
    bool editFaceLabel(const QString& label, const QString& newLabel);

    FaceAuthResult face_regist_images(const QString& label, vector<Mat>& mats);
    FaceAuthResult face_detect_ex(Mat& mat_src, Mat& mat_gray, Mat& mat_withrect, Rect& rect);
    FaceAuthResult face_predict_ex(Mat& mat_gray, FaceRecogResult& result);
private:

    String m_face_detect_path;
    CascadeClassifier m_cascade;

    vector<String> m_face_model_paths;
    vector<CVModel> m_models;
};


#endif // USE_OPENCV
#endif // FACEAUTHENTICATECV_H
